<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>去哪吃</title>
  <style>
    body {
      margin: 0;
      padding: 0;
      font-family: Arial, sans-serif;
      background-color: #f5f5f5;
    }
    header {
      background-color: #ff6d6d;
      color: #fff;
      text-align: center;
      padding: 10px;
    }
    main {
      padding: 10px;
    }
    button {
      display: block;
      margin: 0 auto;
      padding: 10px;
      background-color: #ff6d6d;
      color: #fff;
      border: none;
      border-radius: 5px;
      font-size: 16px;
      cursor: pointer;
    }
    p {
      text-align: center;
      font-size: 24px;
      margin-top: 20px;
      color: #333;
    }
    footer {
      text-align: center;
      font-size: 14px;
      color: #999;
      margin-top: 20px;
    }
  </style>
</head>
<body>
  <header>
    <h1>去哪吃</h1>
  </header>
  <main>
    <button id="randomBtn">推荐一个去处</button>
    <p id="result"></p>
  </main>
  <footer>
    <p>上次选择的楼层：<b><span id="lastFloor">{{lastFloor}}</span>楼</b></p>
    <!-- <p>上上次选择的楼层：<span id="lastLastFloor">{{lastLastFloor}}</span></p> -->
  </footer>
  <script>
    const now = new Date();
    const hour = now.getHours();
    const isLunchTime = hour >= 11 && hour < 14;
    const isDinnerTime = hour >= 17 && hour < 20;

    const buildingOptions = [
      { name: '一号楼B座', floors: [2, 3, 4, 5, 6] },
      { name: '二号楼A座', floors: [3, 4, 5] },
      { name: '二号楼B座', floors: [3, 4, 5] },
      { name: '二号楼C座', floors: [3, 4] }
    ];

    const randomBtn = document.getElementById('randomBtn');
    const result = document.getElementById('result');
    const lastFloorEl = document.getElementById('lastFloor');
    const lastLastFloorEl = document.getElementById('lastLastFloor');
    let lastFloor = localStorage.getItem('lastFloor');
    let lastLastFloor = localStorage.getItem('lastLastFloor');

    let selectedBuilding = null;

    if (lastFloor) {
      lastFloorEl.textContent = lastFloor;
    }

    // if (lastLastFloor) {
    //   lastLastFloorEl.textContent = lastLastFloor;
    // }

    randomBtn.addEventListener('click', () => {
    //   if (isLunchTime) {
    //     selectedBuilding = buildingOptions[Math.floor(Math.random() * 2)];
    //   } else if (isDinnerTime) {
        selectedBuilding = buildingOptions[Math.floor(Math.random() * buildingOptions.length)];
    //   }

      if (selectedBuilding) {
        const floorOptions = selectedBuilding.floors;
        let floor = floorOptions[Math.floor(Math.random() * floorOptions.length)];
        while (lastFloor === `${selectedBuilding.name}${floor}`) {
          floor = floorOptions[Math.floor(Math.random() * floorOptions.length)];
        }
        result.innerHTML = `今天去<b>${selectedBuilding.name}${floor}楼</b>吃${isLunchTime ? '午' : '晚'}餐吧！`;
        lastLastFloor = lastFloor;
        lastFloor = `${selectedBuilding.name}${floor}`;
        // lastLastFloorEl.textContent = lastLastFloor;
        lastFloorEl.textContent = lastFloor;
        localStorage.setItem('lastLastFloor', lastLastFloor);
        localStorage.setItem('lastFloor', lastFloor);
      } else {
        result.textContent = '现在不是用餐时间哦！';
      }
    });
  </script>
</body>
</html>